<template>
  <div>
    <div class="accountReport">
      <!-- 标题 -->
      <div class="accountReport-title">核算报告下载</div>


      <!-- 条件筛选 -->
      <!-- <div class="accountReport-condition">
        <div class="accountReport-condition-form">
          <normal-form-plus
            :formModel="formModel"
            :config="config"
            :plus="plus"/>
        </div>
        <div class="accountReport-condition-btn">
          <el-button>查询</el-button>
          <el-button>重置</el-button>
          <el-button @click="add">新增</el-button>
        </div>
      </div> -->


      <!-- 表格-核算报告 -->
      <div class="accountReport-report">
        <normal-table
          :tableData="tableData"
          :paginationConfig="paginationConfig"
          :tableLabel="tableLabel"
          :operationConfig="operationConfig"
          :operationList="operationList"
          @event="handleEvent"
          @changePage="changePage"></normal-table>
      </div>

      <!-- 选择GHG或者ISO -->
      <el-dialog
        title="语言选择"
        :visible.sync="modifyWindow"
        width="60%"
        class="form">
        <!-- form表单 -->
        <div class="formData">
          <normal-form
            :formModel="addFormModel"
            :config="addConfig"
            :plus="addPlus"/>
        </div>
        <span slot="footer" class="form-footer">
              <el-button type="primary" @click="getEnterpriseReportDownload()" class="confirm">确 定</el-button>
              <el-button @click="modifyWindow = false">取 消</el-button>
            </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import NormalTable from '@/components/NormalTable'
import NormalFormPlus from '@/components/NormalFormPlus'
import NormalForm from '@/components/NormalForm'

export default {
  name: 'accountReport',
  components: {
    NormalTable,
    NormalFormPlus,
    NormalForm
  },
  mounted() {
    this.getEnterpriseReportDownloadByPage();
  },
  data() {
    return {
      addFormModel: {
        language: '',
      },
      addConfig: [
        {
          id: '1',
          edit: true,
          type: 'select',
          model: 'language',
          name: '语言类型',
          props: {
            placeholder: "语言类型",
            options: [
              {label: '中文', value: '1'},
              {label: '英文', value: '2'},
              {label: '韩文', value: '3'}
            ]
          }
        }
      ],
      addPlus: {},
      modifyWindow: false,
      focusId: '',
      formModel: {
        name: ''
      },
      config: [
        {
          id: 1,
          items: [
            {
              id: '1',
              edit: true,
              type: 'input',
              span: 6,
              model: 'modelLevel',
              name: '',
              props: {
                placeholder: "报告名称",

              }
            },
            {
              id: '2',
              edit: true,
              type: 'select',
              span: 6,
              model: 'modelLevel',
              name: '',
              props: {
                placeholder: "核算周期",
                options: [
                  {value: '1', label: '1'},
                  {value: '2', label: '2'}
                ]
              }
            }
          ]
        },
      ],
      plus: {},
      tableData: [],
      paginationConfig: {
        total: 10,
        page: 1,
        pageSize: 10,
        show: true
      },
      operationList: [
        {
          name: '下载',
          order: 1,
          buttonClass: 'primary',
          plus: {}
        }
      ],
      operationConfig: {select: false},
      tableLabel: [
        {
          prop: "order",
          label: "序号",
          width: 70
        },
        {
          prop: "fileName",
          label: "文件名称",
          // width:200
        },
        {
          prop: "type",
          label: "报告类型",
          codeTable: {
            '100': 'ISO',
            '101': 'GHG',
          }
        },
        {
          prop: "creator",
          label: "创建者",
          // width:200
        },
        {
          prop: "@createTime",
          label: "创建时间",
          // width:200
        },
      ],

    }
  },
  methods: {
    add() {
      this.$router.push("/enterpriseCarbonAccounting/carbonEmissionManage/newAccountReport")
    },
    // 处理表格点击事件
    handleEvent(order, row) {
      if (order === 1) {
        this.focusId = row.id;
        this.modifyWindow = true;
      }
    },
    // 分页点击事件
    changePage() {

    },
    // 获得核算报告分页
    getEnterpriseReportDownloadByPage() {
      this.$API.enterprise.getEnterpriseReportDownloadByPage({
        name: '',
        pageNo: this.paginationConfig.page,
        pageSize: this.paginationConfig.pageSize,
      }).then(response => {
        console.log(JSON.stringify(response))
        this.tableData = response.data.list
        // console.log(JSON.stringify(this.tableData))
        this.paginationConfig.total = response.data.total
      })
    },
    // 创建核算报告 语言
    getEnterpriseReportDownload() {
      this.modifyWindow = false
      this.$API.enterprise.getEnterpriseReportDownload({
        downloadId: this.focusId,
        language: this.addFormModel.language
      }).then(response => {
        const a = document.createElement('a')
        a.href = response
        a.download = '温室气体报告.docx' // 下载后文件名
        a.style.display = 'none'
        document.body.appendChild(a)
        a.click() // 点击下载
        document.body.removeChild(a) // 下载完成移除元素
      })
    }

  }
}
</script>

<style lang="less" scoped>
.a-pos {
  position: fixed;
  top: 240px;
  right: 30px;
  width: 100px;
  height: 20px;
  // background-color: #000;
}

.accountReport {

  height: 680px;
  overflow: hidden;
  padding: 15px 10px;
  // 标题
  .accountReport-title {
    font-size: 16px;
    font-weight: bold;
  }

  .accountReport-condition {
    display: flex;

    .accountReport-condition-form {
      flex: 3;
    }

    .accountReport-condition-btn {
      flex: 1;
    }
  }

  // 核算报告表格
  .accountReport-report {
    .accountReport-history-title {
      font-size: 14px;
    }
  }
}
</style>
